<template>
  <div
    class="dashboard-page"
    v-loading="loading.status"
    :element-loading-text="loading.txt"
    v-loading.fullscreen.lock="loading.full"
  ></div>
</template>
<script type="text/javascript">
import store from "../../store/index.js";
import Global from "../../tools/global";
import { setTimeout } from "timers";
export default {
  data() {
    return {
      loading: {
        status: true,
        txt: "正在验证...",
        full: true,
      },
      routeData: [],
      sunNmber: 0,
    };
  },
  created() {
    this.checkToken();
  },
  methods: {
    checkToken() {
      var token = sessionStorage.getItem("token");
      this.loading.status = true;

      let success = (res) => {
        let data = res.data;
        this.loading.txt = "验证成功...";
        this.loading.status = false;

        sessionStorage.setItem(
          "user_info_str",
          JSON.stringify(deep_clone(data.userinfo))
        );
        sessionStorage.setItem("manage_url", data.manage_url);
        sessionStorage.setItem("personal_url", data.personal_url);
        sessionStorage.setItem("ItcJwtToken", data.userinfo.ItcJwtToken);
        store.commit("SET_USERINFO", data.userinfo);

        this.$g.user_id = data.userinfo.id;
        var routerData = this.checkRouter();
        this.$router.addRoutes(routerData);
        //默认跳转首页
        var redirectUrl = "/";
        if (sessionStorage.getItem("paramString") != "/home") {
          redirectUrl = sessionStorage.getItem("paramString");
          sessionStorage.removeItem("paramString");
        }
        this.$router.push(redirectUrl);
      };

      let fail = (data) => {
        if (
          token == "--" &&
          !in_array(Global.decisionPlatform, Global.loginModule)
        ) {
          window.location.href =
            sessionStorage.getItem("host_addr") +
            "/" +
            sessionStorage.getItem("paramString");
        } else {
          this.loading.txt = "验证失败...";
          this.$message.error(data.msg);
          //2后跳回首页
          setTimeout(() => {
            window.location.href = sessionStorage.getItem("host_addr");
          }, 1000);
        }
      };

      this.$ajax.get("api/login/new_login", {
        params: {},
        func: { success: success, fail: fail },
      });
    },
  },
};
</script>